import java.util.*;

public class Place implements Lookable
{
	private String name;
	private Location loc;	// location within the enclosing Area
	private boolean locked;	// determines player access into/out of Place to other Places
	private String description;
	private ArrayList<Entity> ents;

	public Place(String name, Location loc) {
		this.name = name;
		this.loc = loc;
		this.locked = false;
		this.description = name + "'s DEFAULT DESCRIPTION";
		this.ents = new ArrayList<Entity>();
	}

	public Place(String name, Location loc, String description, ArrayList<Entity> ents) {
		this.name = name;
		this.loc = loc;
		this.locked = false;
		this.description = description;
		this.ents = ents;
	}

	public String getName() {
		return name;		
	}

	public Location getLocation() {
		return loc;
	}

	public boolean isLocked() {
		return locked;
	}
	
	public void setLocked(boolean locked) {
		this.locked = locked;
	}

	public String look() {
		return description;
	}

	public void addEntity(Entity ent) {
		ents.add(ent);
	}
	
	public void removeEntity(Entity ent) {
		ents.remove(ent);
	}

	public ArrayList<Entity> getEntities() {
		return ents;
	}
	
	/* 
	 * @return the Entity with the specified name or null
	 */
	public Entity getEntityWithName(String name) {
		for(Entity ent : ents) {
			if(ent.getName().equals(name)) {
				return ent;
			}
		}
		return null;
	}
	
	/*
	 * @return a String containing the direction from this Place to otherPlace 
	 */
	public String getDirectionTowards(Place otherPlace) {
		return loc.getDirectionTowards(otherPlace.getLocation());
	}
}